package com.lovar.gaming.common.security.handler;

import cn.dev33.satoken.exception.NotLoginException;
import com.lovar.gaming.core.domain.R;
import com.lovar.gaming.core.enums.SysMessageCode;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理者
 *
 * @date 2024/8/9
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(NotLoginException.class)
    public R<Void> handleNotLoginException(NotLoginException e, HttpServletRequest request) {
        String requestURI = request.getRequestURI();
        log.error("handleNotLoginException >>> 请求URI: {} | 错误: {}", requestURI, e.getMessage());
        return R.fail(SysMessageCode.LOGIN_EXPIRE);
    }
}
